package com.gg.fmallspringboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gg.fmallspringboot.entity.Product;
import com.gg.fmallspringboot.mapper.ProductMapper;
import com.gg.fmallspringboot.model.Result;
import com.gg.fmallspringboot.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者:Miki
 * 时间:2021/6/21 12:47
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product getOne(String proId) {

        return productMapper.selectOne(proId);
    }

    @Override
    public Result<Product> threeNewProduct() {
        List<Product> products = productMapper.selectRecommendProducts();
        Result result;
        if (products==null){
            result = new Result(1,"查询失败");
        }else {
            result = new Result(0,"查询成功",products);
        }
        return result;
    }

    @Override
    public Result<Product> selectProductByCategoryId(Integer categoryId) {
        List<Product> products = productMapper.selectProductByCategoryId(categoryId);
        Result result;
        if (products==null){
            result = new Result(1,"查询失败");
        }else {
            result = new Result(0,"查询成功",products);
        }
        return result;
    }
}
